<div class="panel">
    <div class="panel-heading">
        <h3 class="panel-title">库存占用报表</h3>
    </div>
    <div class="panel-body">
        <div class="container-fluid">
            <form id="search-form" class="search-form">
                <div class="col-sm-12 col-md-4  add-space">
                    <div class="input-group input-group-md">
                        <span class="input-group-addon">账号</span>
                        <select class="chosen-select form-control" tabindex="-1" name="account_id" data-name-group="common">
                            <option value="" class="empty-opt">-- 请选择 --</option>
                            <volist name="accounts" id="item">
                                <option value="{$item.id}" >{$item.name}</option>
                            </volist>
                        </select>
                        <input name="page" id="page" type="hidden" />
                    </div>
                </div>
                <div class="col-sm-12 col-md-4  add-space">
                    <div class="input-group input-group-md">
                        <span class="input-group-addon">是否退税</span>
                        <select class="form-control" tabindex="-1" name="export_tax_rebate"
                                data-name-group="common">
                            <option value="" class="empty-opt">-- 请选择 --</option>
                            <option value="1"
                            <if condition="$info['export_tax_rebate'] heq 1">selected="selected"</if>>是
                            </option>
                            <option value="0"
                            <if condition="$info['export_tax_rebate'] heq 0">selected="selected"</if>>否
                            </option>
                        </select>
                    </div>
                </div>
                <div class="col-sm-12 col-md-4  add-space">
                    <div class="input-group input-group-md">
                        <span class="input-group-addon">公司主体</span>
                        <select type="text" tabindex="-1" name="enterprise_dominant" class="form-control option">
                            <option value="">-- 请选择 --</option>
                            <volist name="enterprise_dominant" id="item">
                                <option value="{$key}"
                                <if condition="$info['enterprise_dominant'] eq $key">selected="selected"</if>>{$item}
                                </option>
                            </volist>
                        </select>
                    </div>
                </div>
                <div class="col-sm-12 col-md-3  add-space">
                    <div class="input-group input-group-md">
                        <span class="input-group-addon">SKU</span>
                        <input class="form-control" type="text" name="sku" value="{$info['sku']}">
                    </div>
                </div>
                <div class="col-sm-12 col-md-3  add-space">
                    <div class="input-group input-group-md">
                        <span class="input-group-addon">ShipmentId</span>
                        <input class="form-control" type="text" name="shipmentid" value="">
                    </div>
                </div>
                <div class="col-md-2 add-space">
                    <input class="btn btn-primary jsSearchBtn" type="button" value="搜索">
                </div>
            </form>
        </div>
        <div class="clearfix"></div>
        <hr>
        <table class="table table-striped  table-hover" cellspacing="0" width="100%">
            <thead>
            <tr>
                <td>SKU</td>
                <td>中文名称</td>
                <td>数量</td>
                <td>是否出口退税</td>
                <td>公司主体</td>
                <td>状态</td>
                <td>帐号</td>
                <td>销售员</td>
                <td>ShipmentId</td>
            </tr>
            </thead>
            <tbody id="info"></tbody>
        </table>
    </div>
    <div class="clearfix clear"></div>
    <div id="pagecount"></div>
</div>

<script type="text/javascript">
    $(document).ready(function (){
        $('select.chosen-select').chosen({
            no_results_text : '没有找到',    // 当检索时没有找到匹配项时显示的提示文本
            disable_search_threshold : 2,  // 个以下的选择项则不显示检索框
            search_contains : true         // 从任意位置开始检索
        });

        $('#pagecount').on('click','span a',function(){
            var rel = $(this).attr("rel");
            $('#page').val(rel);
            getData();
        });

        $(".jsSearchBtn").click(function(){
            $('#page').val(1);
            getData();
        });

    });

    /**
     * 获取当页数据
     */
    function getData(){

        $.ajax({
            type: 'POST',
            url: '__URL__/occupiedInventoryGet',
            data: $('#search-form').serialize(),
            dataType:'json',
            success:function(arr){
                total = arr.total; //总记录数
                pageSize = arr.pageSize; //每页显示条数
                curPage = arr.page; //当前页
                totalPage = arr.totalPage; //总页数
                var list = arr.result;

                var content = '';
                if(typeof(list) == "undefined"){
                    content = '';
                    layer.msg("查询结果为空！", {icon : 5});
                } else{
                    $.each(list,function(index,array){ //遍历json数据列
                        content += "<tr>";
                        content += "<td>" + array['sku'] + "</td>";
                        content += "<td>" + array['sku_name'] + "</td>";
                        content += "<td>" + array['quantity'] + "</td>";
                        content += "<td>" + array['export_tax_rebate'] + "</td>";
                        content += "<td>" + array['enterprise_dominant'] + "</td>";
                        content += "<td>" + array['status'] + "</td>";
                        content += "<td>" + array['account_name'] + "</td>";
                        content += "<td>" + array['seller'] + "</td>";
                        content += "<td>" + array['shipmentid'] + "</td>";
                        content += "</tr>";

                    });
                }
                $('#info').html(content);
                getPage();

            },
            error:function(){
                layer.msg("数据出错，请联系IT！", {icon : 5});
            }
        });
    }

    /**
     * 分页展示
     */
    function getPage(){

        if(curPage>totalPage)curPage=totalPage;
        if(curPage<1)curPage=1;
        var pageStr="<span class='span'>共"+total+"条</span><span class='span'>"+curPage+"/"+totalPage+"</span>"
        if(curPage==1){
            pageStr += "<span class='span'>首页</span><span class='span'>上一页</span>";
        }else{
            pageStr += "<span><a class='a' href='javascript:void(0)' rel='1'>首页</a></span>" +
                    "<span><a class='a' href='javascript:void(0)' rel='"+(curPage-1)+"'>上一页</a></span>"
        }
        if(curPage>=totalPage){
            pageStr += "<span class='span'>下一页</span><span class='span'>尾页</span>";
        }else{
            pageStr += "<span><a class='a' href='javascript:void(0)' rel='"+(parseInt(curPage)+1)+"'>下一页</a></span>" +
                    "<span><a class='a' href='javascript:void(0)' rel='"+totalPage+"'>尾页</a></span>";
        }
        $("#pagecount").html(pageStr);
    }
</script>